package test.socket;

import java.io.IOException;

import hyl.base.net.IpgReader;
import hyl.base.net.bio.BIOData1;
import hyl.base.net.bio.BIOSocketCli;
import hyl.core.MyFun;
import hyl.core.net.pg.Netpg2Cmd;


public class testbioclient {
	public static void main(String[] arg) throws IOException {
		BIOSocketCli bioc = new BIOSocketCli("127.0.0.1", 9090);
		IpgReader br = bioc.startReader();
		testbioclient tbs = new testbioclient();
		// tbs.test1收发数据3次(bioc, br);
		// tbs.test2发送指令(bioc, br);
	   // tbs.test3url服务调用(bioc);
		//tbs.test4连续发送(bioc, br);
	}

	public void test4连续发送(BIOSocketCli bioc, IpgReader br) throws IOException {
		long n = MyFun.getMs();
		for (int i = 0; i < 100000; i++) {
			bioc.send(BIOData1.B类型_数据, ("测试数据" + i).getBytes());
		}
		bioc.send(BIOData1.B类型_数据, ("bye").getBytes());
		long m = MyFun.getMs() - n;
		System.out.println("用时=" + m + "m秒");
	}

//	public void test3url服务调用(BIOSocketCli 客户端) {
//		System.out.println("路径=" + URIServicesDao.do读取服务路径(客户端, "test"));
//
//	}
//
//	public void test3查询服务列表(BIOSocketCli 客户端) {
//		System.out.println("路径=" + URIServicesDao.do查询服务列表(客户端));
//	}

	public void test2发送指令(BIOSocketCli bioc, IpgReader br) throws IOException {

		Netpg2Cmd cmd = new Netpg2Cmd();
		// 请求指令

		cmd.setS指令("test1");
		cmd.setS字符参数("测试90877");
		cmd.setB字节参数("排除自己".getBytes());
		bioc.send(BIOData1.B类型_指令, cmd.toSendBytes());
		byte[] data = br.pullData();
		if (data != null)
			System.out.println("收到服务端消息::" + new String(data));
	}

	public void test1收发数据3次(BIOSocketCli bioc, IpgReader br) {

		br.send(BIOData1.B类型_数据, "开始发送测试了哦.....".getBytes());
		byte[] data;
		int i = 0;
		while ((data = br.pullData()) != null) {
			System.out.println("收到服务端消息::" + new String(data));
			if (i++ < 3)
				br.send(BIOData1.B类型_数据, ("反馈服务端" + i).getBytes());
		}

	}

}
